home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)vt2tx.c V1.5 5/2/95";
- #endif
- /* ====================================================================
- vt2tx - convert vector text fonts to hardware text in a viewfile
- --------------------------------------------------------------------
- VERSION 1.0
- SYNOPSIS vt2tx <device-string> <viewfile-source> <viewfile-destination> [<fontsize>]
- DESCRIPTION Converts all vector text fonts in a viewfile to hardware
- text fonts. If the user specifies a fontsize (1,2,3, or 4)
- then the program will set the hardware font to that size.
- If no fontsize is specified, then the program uses the
- largest font that will fit in the same area when the
- view is drawn to the full screen.
-
- Once the changes are made the user should be able to go into
- DV-Draw and make the appropriate fine changes if
- necessary. The utility will correctly convert all
- vector texts in included subdrawings; referenced
- subdrawings will be left as is.
-
- HOW IT WORKS
-
- There are three possibilities requiring consideration in a
- view when converting:
-
- (1) if it is a vector text object (OT_VTEXT):
- (a) create a version in regular text (VOtxCreate);
- (b) set the size to the user-specified value or if, no value
- was specified, choose the largest font that will fit in
- the space occupied by the vector font (VOtxAtSet)
- (c) replace the vector text with the regular text.
- (using VOdrObReplace).
- (2) if it is a included subdrawing (OT_SUBDRAWING), recursively do a
- TobForEachSubobject with the drawing object associated with
- the subdrawing.
- (3) if it is anything else, ignore it.
-
- EXAMPLE vt2tx x:=640x480 dan.v out.v 2
- ================================================================= */
-
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "dvGR.h"
- #include "VOstd.h"
- #include "VOfundecl.h"
- #include "Tfundecl.h"
- #include "GRfundecl.h"
-
- /* Global forward function declarations */
- ADDRESS ReplaceVtextWithText V_P_ ((OBJECT object, OBJECT ParentDrawing));
-
- /* Local forward function declarations */
-
- DRAWPORT drawport;
- INT text_size = 0, largest_text_size = 0;
- OBJECT DefaultTextBackcolor = 0;
-
- LOCAL CHAR ErrMsg[]= "Wrong number of arguments.\n";
- LOCAL CHAR Usage[]= "Usage: %s <device-string> <viewfile-source> <viewfile-destination> [<textsize>]\n";
- LOCAL CHAR *DVpath = NULL; /* Use value of DVPATH config variable */
-
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- VIEW view;
- SCREEN_OBJECT screen;
- OBJECT ParentDrawing;
- int argc = 0;
- char **argv;
-
- make_argv(&argc,&argv,GetCommandLine());
-
- /* Make sure there are at least 3 arguments */
- if (argc < 4)
- {
- (VOID) fprintf (stderr, ErrMsg);
- (VOID) fprintf (stderr, Usage, argv[0]);
- exit (EXIT_ERR);
- }
-
- /* Initialize program */
- (VOID) TInit (DVpath, (CHAR *) NULL);
- screen = TscOpen (argv[1], (CHAR *) NULL);
- view = TviLoad (argv[2]);
- drawport = TdpCreate (screen, view, (RECTANGLE *) NULL,
- (RECTANGLE *) NULL);
-
- /* Get arguments for traversal function, ReplaceVtextWithText. */
- GRget (V_NUM_FONTS, &largest_text_size, V_END_OF_LIST);
- ParentDrawing = TviGetDrawing (view);
- if (argc >= 5)
- { /* Get text size to use. */
- (VOID) sscanf (argv[4], "%d", &text_size);
- text_size = S_MAX (1, text_size);
- text_size = S_MIN (largest_text_size, text_size);
- }
-
- DefaultTextBackcolor = VOcoCreate (COLOR_NAME, "black");
-
- /* Recursively replace all regular text object */
- (VOID) TobForEachSubobject (ParentDrawing,
- (TOBFOREACHSUBOBJFUNPTR)ReplaceVtextWithText,
- (ADDRESS) ParentDrawing);
-
- /* Save new view file and clean-up */
- if (!TviSave (view, argv[3]))
- (VOID) fprintf (stderr, "%s: Could not save view\n", argv[3]);
- TdpFree (drawport);
- (VOID) TscClose (screen);
- (VOID) TTerminate ();
- return EXIT_OK;
- }
-
- /* ********************************************************************** */
- /* Function that replaces vector text object with regular text equivalent */
- ADDRESS
- ReplaceVtextWithText (object, ParentDrawing)
- OBJECT object;
- OBJECT ParentDrawing;
- {
- INT obtype, text_size_guess, text_direction, width, height;
- OBJECT ptobj, txobj, NewParentDrawing;
- DV_POINT vtsize;
- ATTRIBUTES attr;
- RECTANGLE wvp, pixoffset, svp;
- CHAR *string;
-
- /* If it is of vector text type replace it with regular text,
- else if it is an included subdrawing, descend recursively and repeat,
- else just ignore. */
- obtype = VOobType (object);
- if (obtype == OT_VTEXT)
- {
- /* construct a close match of vector text with regular text */
- ptobj = VOobPtGet (object, 1);
- VOobAtGet (object, &attr);
-
- /* Make sure there is a background color */
- if (attr.background_color == EMPTY_FIELD)
- attr.background_color = DefaultTextBackcolor;
-
- string = VOvtGetString (object);
-
- /* Calculate the text size */
- if (text_size > 0)
- { /* User specified the text size */
- attr.text_size = text_size;
- }
- else
- { /* Make a best guess about the text size */
-
- /* Calculate the size of the vector text in screen coordinates */
- VOobBox (object, &wvp, &pixoffset);
- (VOID) TdpWorldToScreen (drawport, &wvp.ll, &svp.ll);
- (VOID) TdpWorldToScreen (drawport, &wvp.ur, &svp.ur);
- svp.ll.x += pixoffset.ll.x;
- svp.ll.y += pixoffset.ll.y;
- svp.ur.x += pixoffset.ur.x;
- svp.ur.y += pixoffset.ur.y;
- vtsize.x = 1 + S_ABS (svp.ur.x - svp.ll.x);
- vtsize.y = 1 + S_ABS (svp.ur.y - svp.ll.y);
-
- /* Choose the largest hardware font that fits */
- if (attr.text_direction == VERTICAL_TEXT)
- text_direction = VERTICAL_TEXT;
- else
- text_direction = HORIZONTAL_TEXT;
-
- for (text_size_guess = largest_text_size;
- text_size_guess > 0;
- text_size_guess--)
- {
- VOgChSize (text_size_guess);
- VOgTextsize (string, text_direction, &width, &height);
- if (width <= vtsize.x && height <= vtsize.y)
- break;
- }
-
- if (text_size_guess <= 0)
- text_size_guess = 1;
-
- /* Now set the size */
- attr.text_size = text_size_guess;
- }
-
- txobj = VOtxCreate (string, ptobj, &attr);
-
- /* Make sure slots get copied over */
- /* This assumes dynamics are kept in slots and will be copied properly */
- VOobCopySlots (txobj, object);
-
- (VOID) VOdrObReplace (ParentDrawing, object, txobj); /* replace! */
- }
- else if (obtype == OT_SUBDRAWING)
- {
- /* We are looking at a subdrawing. If the subdrawing is included, then
- descend recursively and search again for regular text to replace */
- if (VOsdViKeep (object, -1 /* Invalid value */ ))
- {
- NewParentDrawing = VOsdDrGet (object);
- (VOID) TobForEachSubobject (NewParentDrawing,
- (TOBFOREACHSUBOBJFUNPTR)ReplaceVtextWithText,
- (ADDRESS) NewParentDrawing);
- }
- }
- return NULL;
- }
-